﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class YCAFSSTYLE : DocumentBase
    {
        #region-------------Properties-----------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        YCAFSSTYLEData m_Data, m_DataX;
        public DataSet setUI=new DataSet();
        public DataSet dsParamaters;
        public DataRow dwABPOS;
        public INTEXDBC INTEXDBC;
        private DataRow dwUI;
        DataTable tableUI;                
        #endregion
        public YCAFSSTYLE()
        {
            InitializeComponent();
            this.Name = "款号信息总览";
           
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            orlReadCommand = OracleDB.CreateCommand();
            orlReadCommand.Parameters.Add("OrdNum", OracleType.NVarChar).Value = "";
            m_Data = new YCAFSSTYLEData();
            m_Data.OracleDB = this.OracleDB;
            m_Data.proxy = this.proxy;
            INTEXDBC = new INTEXDBC(OracleDB, proxy);
            tableUI = new DataTable("UIData");
            tableUI.Columns.Add("ARTICLE", typeof(string));
            tableUI.Columns.Add("ARTTYPE", typeof(string));
            tableUI.Columns.Add("COLL", typeof(string));
            tableUI.Columns.Add("REASON", typeof(string));
            tableUI.Columns.Add("PRDGRP", typeof(string));
            tableUI.Columns.Add("ARTGRP", typeof(string));
            tableUI.Columns.Add("MATERIAL", typeof(string));
            tableUI.Columns.Add("STANDARD", typeof(string));
            tableUI.Columns.Add("SAFTY", typeof(string));
            tableUI.Columns.Add("PURCHASER", typeof(string));
            tableUI.Columns.Add("SIZE", typeof(string));
        }

        private void InitDataBinding()
        {
           
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                dwUI = tableUI.NewRow(); 
                InitDataBinding();
                txtARTICLE.Focus();
                
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return;

        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    DataSet setResult = new DataSet();
                    setUI.Clear();
                    setUI.AcceptChanges();
                    string ARTICLE = txtARTICLE.Text.Trim();
                    string ARTTYPE = txtARTTYPE.Text.Trim();
                    string COLL = txtCOLL.Text.Trim();
                    string REASON = txtREASON.Text.Trim();
                    string PRDGRP = txtPRDGRP.Text.Trim();
                    string ARTGRP = txtARTGRP.Text.Trim();
                    string MATERIAL = txtMATERIAL.Text.Trim();
                    string STANDARD = txtSTANDARD.Text.Trim();
                    string SAFTY = txtSAFTY.Text.Trim();
                    string PURCHASER = txtPURCHASER.Text.Trim();
                    string SIZE = txtSIZE.Text.Trim();
                    if (ARTTYPE == "")
                    {
                        ARTTYPE = "XXXXXX";
                    }
                    if (COLL == "")
                    {
                        COLL = "XXXXXX";
                    }
                    if (REASON == "")
                    {
                        REASON = "XXXXXX";
                    } 
                    if (PRDGRP == "")
                    {
                        PRDGRP = "XXXXXX";
                    } 
                    if (ARTGRP == "")
                    {
                        ARTGRP = "XXXXXX";
                    }
                    if (MATERIAL == "")
                    {
                        MATERIAL = "XXXXXX";
                    } 
                    if (STANDARD == "")
                    {
                        STANDARD = "XXXXXX";
                    }
                    if (SAFTY == "")
                    {
                        SAFTY = "XXXXXX";
                    } 
                    if (PURCHASER == "")
                    {
                        PURCHASER = "XXXXXX";
                    } 
                    if (SIZE == "")
                    {
                        SIZE = "XXXXXX";
                    } 

                    dwUI["ARTICLE"] = ARTICLE;
                    dwUI["ARTTYPE"] = ARTTYPE;
                    dwUI["COLL"] = COLL;
                    dwUI["REASON"] = REASON;
                    dwUI["PRDGRP"] = PRDGRP;
                    dwUI["ARTGRP"] = ARTGRP;
                    dwUI["MATERIAL"] = MATERIAL;
                    dwUI["STANDARD"] = STANDARD;
                    dwUI["SAFTY"] = SAFTY;
                    dwUI["PURCHASER"] = PURCHASER;
                    dwUI["SIZE"] = SIZE;
                    setResult = m_Data.BuildYCAFSSTYLEData(dwUI);
                    setUI.Merge(setResult);
                    MasterDg.DataContext = setUI.Tables["FSSTAMM"];
                    
                }
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
               
       
        private void btnEXCEL_Click(object sender, RoutedEventArgs e)
        {
            m_DataX = new YCAFSSTYLEData(dicParamater);
            m_DataX.exAgent._app.Visible = false;
            m_DataX.OracleDB = this.OracleDB;
            m_DataX.proxy = this.proxy;
            YCAFSSTYLEReport m_rpt = new YCAFSSTYLEReport(dicParamater);
            m_rpt.dsSource = setUI;
            m_rpt.PrintType = "OpenExcel";
            m_rpt.exAgent = m_DataX.exAgent;
            m_rpt.WriteExcelReport("EXCEL");
        }                   

        private void txtART_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Enter) return;
            btnQuery_Click(null,null);

        }

    }
}
